//
//  FriendCell.m
//  QQ好友列表1
//
//  Created by lanou3g on 15/11/19.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "FriendCell.h"
#import "FriendCell.h"
#import "Friend.h"
#import "UIImageView+WebCache.h"
#define margin 2
#define usernameFont [UIFont systemFontOfSize:20]
#define signatureFont [UIFont systemFontOfSize:10]

@interface FriendCell ()

/**
 *  用户头像
 */
@property (nonatomic, strong) UIImageView *icon;

/**
 *  用户名字
 */
@property (nonatomic, strong) UILabel *username;

/**
 *  用户签名
 */
@property (nonatomic, strong) UILabel *signature;

/**
 *  vip图像
 */
@property (nonatomic, strong) UIImageView *vipIcon;

/**
 *  联网状态
 */
@property (nonatomic, strong) UIImageView *network;

@end

@implementation FriendCell


+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"friend";
    FriendCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[FriendCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        
        
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        // 初始化子控件
        [self setupSubViews];
        
        
    }
    return self;
}


- (void)setupSubViews
{
    self.icon = [[UIImageView alloc] init];
    self.icon.layer.cornerRadius = 20;
    self.icon.clipsToBounds = YES;
    self.username = [[UILabel alloc] init];
    self.username.font = usernameFont;
    self.username.textColor = [UIColor redColor];
    self.signature = [[UILabel alloc] init];
    self.signature.font = signatureFont;
    self.vipIcon = [[UIImageView alloc] init];
    self.network = [[UIImageView alloc] init];
    
    [self.contentView addSubview:self.icon];
    [self.contentView addSubview:self.username];
    [self.contentView addSubview:self.signature];
    [self.contentView addSubview:self.vipIcon];
    [self.contentView addSubview:self.network];
    
}

// 计算子控件的frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // cell的宽度
    CGFloat cellW = self.frame.size.width;
    
    self.icon.frame = CGRectMake(margin, margin, 40, 40);
    CGFloat usernameX = CGRectGetMaxX(self.icon.frame) + margin;
    self.username.frame = CGRectMake(usernameX, margin * 2, 100, 14);
    CGFloat sigY = CGRectGetMaxY(self.username.frame) + margin;
    self.signature.frame = CGRectMake(usernameX, sigY + 5 * margin, 200, 14);
    
    CGFloat vipX = CGRectGetMaxX(self.username.frame) + margin;
    self.vipIcon.frame = CGRectMake(vipX, margin, 10, 10);
    self.network.frame = CGRectMake(cellW - 30, 16, 12, 12);
    
    
    
    
}



- (void)setFriendData:(Friend *)friendData
{
    _friendData = friendData;
    
////    self.imageView.image = [UIImage imageNamed:friendData.icon];
//    self.imageView.image = [UIImage imageNamed:@"iconfont-yuyin-2"];
//    self.imageView.layer.cornerRadius = 20;
//    self.imageView.clipsToBounds = YES;
//    
//    self.textLabel.text = friendData.username;
//    // 会员的文字为红色
//    self.textLabel.textColor = friendData.isVip ? [UIColor redColor] : [UIColor blackColor];
//    self.detailTextLabel.text = friendData.objectId;
    
    [self.icon sd_setImageWithURL:[NSURL URLWithString:friendData.iconUrl]];
    self.icon.backgroundColor = [UIColor lightGrayColor];
    self.username.text = friendData.username;
    self.signature.text = [NSString stringWithFormat:@"[在线] %@", friendData.objectId];
    self.network.image = [UIImage imageNamed:@"iconfont-wifi"];
    
}




@end









